import { useState, useMemo } from "react";

export default function App() {
  const [count, setCount] = useState(0);
  const [bool, setBool] = useState(true);
  const result = useMemo(() => {
    console.log("count改变啦~"); // 后续只有 count 改变才会重新执行这个回调函数
    return count * 2;
  }, [count]);

  return (
    <div>
      <span>
        {count} {result}
      </span>
      <span>{bool ? "真" : "假"}</span>
      <button onClick={() => setCount(count + 1)}> + 1</button>
      <button onClick={() => setBool(!bool)}>setBool</button>
    </div>
  );
}
